package com.cunfang.test;

import java.util.HashSet;
import java.util.Set;

public class RunnableDemo implements Runnable{
	public int num;
	public String methodName;
	public static int[] count={1,2,3,4,5,6,7,8,9,10,
								11,12,13,14,15,16,17,18,19,20};
	public static Set<Integer> sellCount = new  HashSet<Integer>();
	public RunnableDemo(int num,String methodName){
		this.num=num;
		this.methodName =methodName;
	}
	public void run() {
		if(this.methodName.equals("sell")){
			System.out.println(sell(num));
		}else{
			System.out.println(back(num));
		}
	}
	public String sell(int num){
		if(!sellCount.contains(num)){
			sellCount.add(num);
			return "购买成功";
		}else{
			return "该座位已经卖出";
		}
	}
	public String back(int num){
		if(sellCount.contains(num)){
			sellCount.remove(num);
			return "退票成功";
		}else{
			return "退票失败";
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		RunnableDemo run1 = new RunnableDemo(20,"sell");
		RunnableDemo run2 = new RunnableDemo(30,"sell");
		new Thread(run1).start();
		new Thread(run2).start();
		run1 = new RunnableDemo(20,"back");
		new Thread(run1).start();
		run2 = new RunnableDemo(20,"sell");
		new Thread(run2).start();
		run2 = new RunnableDemo(15,"sell");
		new Thread(run2).start();
		run1 = new RunnableDemo(30,"back");
		new Thread(run1).start();
	}
	

	

}
